
var iconv = require('iconv-lite');
const jsdom = require("jsdom");
const fs = require("fs");
const { JSDOM } = jsdom;
const { Script } = require("vm");

var content = fs.readFileSync('weixin.html', {encoding:'binary'});
var buf = new Buffer.from(content, 'binary');
//var buf = new Buffer(content, 'binary');
var str = iconv.decode(buf, 'utf-8');
//console.log(str);

const dom = new JSDOM(str, { runScripts: "outside-only" });

const s = new Script(`
    this.href = document.getElementById("sogou_vr_11002601_title_1").href;

//    this.href = "/link?url=dn9a_-gY295K0Rci_xozVXfdMkSQTLW6cwJThYulHEtVjXrGTiVgS_uirRSi2mDgtNJW8k1-0vHE3US39qAfHlqXa8Fplpd9U9EWfVJzoPa7LD-UgMwvH62QZGOGZNcosN5zS0s8ZEdjOqypaxrSojBU96E-24IE5a12UxJYwngjucg-ER1X3eML9QTZuzzQNpWhXwHBj_4WTal1xiE7PPE9kwkIoOdU16mt-GJ4wdJ7XJgb_bTYihu5WL3c9OcK-5HxMROnG6v2CsG6-xMgzQ..&type=2&query=zhaop";
    var b = Math.floor(100 * Math.random()) + 1,
      a = this.href.indexOf("url="),
      c = this.href.indexOf("&k=");
       - 1 !== a && -1 === c && (a = this.href.substr(a + 4 + parseInt("21") + b, 1), this.href += "&k=" + b + "&h=" + a);
`);

dom.runVMScript(s);

console.log(dom.window.href);

const document = dom.window.document;

console.log(document.href)
